Skip to content

Generate ITenantScope for tenant-aware .Biz.cs entities - #97

Merged
nnhy merged 2 commits into
masterfrom
copilot/feature-automatically-implement-itenant-scope
Aug 27, 2026
Merged

Generate ITenantScope for tenant-aware .Biz.cs entities#97
nnhy merged 2 commits into
masterfrom
copilot/feature-automatically-implement-itenant-scope

Conversation

Copilot AI commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

EntityBuilder already injects TenantInterceptor when a table contains TenantId, but generated business classes did not also implement ITenantScope. This change aligns the generated type declaration with the existing interceptor behavior for multi-tenant entities.

  • Generator behavior

    • Update XCode/Code/EntityBuilder.cs so GetBaseClass() appends ITenantScope only for business-class generation (.Biz.cs) when the table has a TenantId column.
    • Keep matching case-insensitive.
    • Avoid duplicating ITenantScope if it is already present in the configured base/interface list.
    • Leave data-class generation (.cs) unchanged.
  • Generated fixtures

    • Refresh affected generated business snapshots for tenant-aware entities:
      • 部门.Biz.cs
      • 角色.Biz.cs
      • 租户关系.Biz.cs
  • Focused coverage

    • Add a targeted generator test covering:
      • tenant-aware business entity => Entity<T>, ITenantScope
      • non-tenant data entity => no automatic ITenantScope

Example generated declaration:

public partial class Role : Entity<Role>, ITenantScope
{
    static Role()
    {
        Meta.Interceptors.Add<TenantInterceptor>();
    }
}

Co-authored-by: nygula <13066114+nygula@users.noreply.github.com>
Copilot AI changed the title [WIP] Add automatic implementation of ITenantScope in Biz.cs Generate ITenantScope for tenant-aware .Biz.cs entities Aug 14, 2026
Copilot AI requested a review from nygula August 14, 2026 05:41
@nnhy
nnhy marked this pull request as ready for review August 27, 2026 15:19
Copilot AI lite review requested due to automatic review settings August 27, 2026 15:19
@nnhy
nnhy merged commit d32208a into master Aug 27, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request updates the XCode entity generator so that tenant-aware business entities (.Biz.cs) automatically implement ITenantScope when the underlying table contains a TenantId column, aligning the generated type declaration with the already-present TenantInterceptor injection behavior.

Changes:

  • Update EntityBuilder.GetBaseClass() to append ITenantScope for tenant-aware business entities (case-insensitive TenantId detection, avoids duplicate insertion).
  • Refresh generated business-class fixtures for tenant-aware membership entities to include ITenantScope.
  • Add a focused unit test to validate tenant-aware business entities implement ITenantScope and include TenantInterceptor.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
XCode/Code/EntityBuilder.cs Appends ITenantScope to generated business-class base list when table has TenantId.
XUnitTest.XCode/Code/EntityBuilderTests.cs Adds a generator test for tenant-aware business entities and interceptor injection.
XUnitTest.XCode/Code/Entity/部门.Biz.cs Updates generated fixture class declaration to include ITenantScope.
XUnitTest.XCode/Code/Entity/角色.Biz.cs Updates generated fixture class declaration to include ITenantScope.
XUnitTest.XCode/Code/Entity/租户关系.Biz.cs Updates generated fixture class declaration to include ITenantScope.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +412 to +424
table = _tables.First(e => e.Name == "Tenant");
builder = new EntityBuilder
{
Table = table,
AllTables = _tables,
Option = option,
};

builder.Execute();
code = builder.ToString();

Assert.DoesNotContain("public partial class Tenant : Entity<Tenant>, ITenantScope", code);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] XCodeTool 自动生成多租户表时,Biz.cs 应默认实现 ITenantScope 接口

4 participants